package com.dmooo.ymx.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.dmooo.ymx.CaiNiaoApplication;
import com.dmooo.ymx.R;
import com.dmooo.ymx.base.BaseActivity;
import com.dmooo.ymx.bean.BalanceRecordListBean;
import com.dmooo.ymx.bean.PddClient;
import com.dmooo.ymx.bean.Response;
import com.dmooo.ymx.bean.UserInfoBean;
import com.dmooo.ymx.common.SPUtils;
import com.dmooo.ymx.config.Constants;
import com.dmooo.ymx.https.HttpUtils;
import com.dmooo.ymx.https.onOKJsonHttpResponseHandler;
import com.dmooo.ymx.my.BalanceActivity;
import com.google.gson.reflect.TypeToken;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cz.msebera.android.httpclient.Header;


public class ZhouZhouLeActivity extends BaseActivity {

    @BindView(R.id.txt_money)
    TextView txtMoney;
//    @BindView(R.id.txt_mess)
//    TextView txtMess;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
        setContentView(R.layout.activity_zhouzhoule);
        ButterKnife.bind(this);
        txtMoney.setText(getIntent().getStringExtra("money"));
//        txtMess.setText(getIntent().getStringExtra("mess"));
        findViewById(R.id.tv_left).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        zhouzhoule();
    }

    @Override
    protected void initUI() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    /**
     * 周周乐
     */
    private void zhouzhoule() {
        String time = String.valueOf(System.currentTimeMillis() / 1000);
        RequestParams requestParams = new RequestParams();
        requestParams.put("data_type", PddClient.data_type);
        requestParams.put("version", PddClient.version);
        requestParams.put("timestamp", time);
        requestParams.put("token", SPUtils.getStringData(ZhouZhouLeActivity.this, "token", ""));
        requestParams.put("type", "yxm.UserBalanceRecord.receiveBonus2");
        Map<String, String> temp = new HashMap<>();
        temp.put("data_type", PddClient.data_type);
        temp.put("version", PddClient.version);
        temp.put("timestamp", time);
        temp.put("token", SPUtils.getStringData(ZhouZhouLeActivity.this, "token", ""));
        temp.put("type", "yxm.UserBalanceRecord.receiveBonus2");
        String sign = PddClient.getSign1(temp);
        requestParams.put("sign", sign);
        HttpUtils.post(Constants.HONGBAO2, requestParams, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {

            }

            @Override
            public void onStart() {
                super.onStart();
                showLoadingDialog();
            }

            @Override
            public void onFinish() {
                super.onFinish();
                closeLoadingDialog();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject jsonObject = new JSONObject(responseString);
                    int code = jsonObject.optInt("code");
                    String msg = jsonObject.optString("msg");
                    if (code == 0) {
                        txtMoney.setText(jsonObject.getString("money"));
//                        intent.putExtra("money", jsonObject.getString("money"));
//                        intent.putExtra("mess", "红包已存至余额~");
//                        startActivity(intent);
                    } else {
                        showToast(msg);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    public void onBackPressed() {
        finish();
    }

    @OnClick(R.id.img_yue)
    public void onViewClicked() {
        UserInfoBean userBean=CaiNiaoApplication.getUserInfoBean();
        Bundle b = new Bundle();
        if (null != userBean && null != userBean.user_msg) {
            b.putString("balance", userBean.user_msg.balance);
            b.putString("user", userBean.user_msg.balance_user);
            b.putString("service", userBean.user_msg.balance_service);
            b.putString("plantform", userBean.user_msg.balance_plantform);
        }
        Intent intent=new Intent(this,BalanceActivity.class);
        intent.putExtras(b);
        startActivity(intent);
    }
}
